import 'package:flutter/material.dart';
import 'package:trip_flutter/util/screen_adapt_helper.dart';

List<String> Card1 = ["images/Card1.png", "酒店", "海外酒店", "爆款", "特价酒店", "民宿 客栈"];
List<String> Card2 = [
  "images/Card2.png",
  "机票",
  "火车票",
  "汽车票·船票",
  "特价机票",
  "专车·租车",
];
List<String> Card3 = ["images/Card3.png", "旅游", "门票", "私家团", "目的地攻略", "定制旅行"];

class Localcard extends StatefulWidget {
  const Localcard({super.key});

  @override
  State<Localcard> createState() => _LocalcardState();
}

class _LocalcardState extends State<Localcard> {
  @override
  Widget build(BuildContext context) {
    return PhysicalModel(
      color: Colors.transparent,
      borderRadius: BorderRadius.all(Radius.circular(4)),
      clipBehavior: Clip.antiAlias,
      child: Column(children: gridNavCards()),
    );
  }

  List<Widget> gridNavCards() {
    List<Widget> items = [];
    items.add(gridItem(Card1, true));
    items.add(gridItem(Card2, false));
    items.add(gridItem(Card3, false));
    return items;
  }

  Widget gridItem(List<String> card, bool first) {
    List<Widget> items = [];
    items.add(mainItem(card));
    items.add(doubleItem(card));
    List<Widget> expandItems = [];
    for (var i in items) {
      expandItems.add(Expanded(flex: 1, child: i));
    }
    return Container(
      height: 88,
      margin: !first ? EdgeInsets.only(top: 6.px) : EdgeInsets.zero,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          // 渐变方向（从左上角到右下角）
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          // 渐变颜色数组
          colors: [Colors.blue, Colors.purple, Colors.pink],
          // 可选：设置颜色过渡位置（0.0到1.0之间）
          stops: [0.0, 0.5, 1.0], // 对应上面三个颜色的位置
        ),
      ),
      child: Row(children: expandItems),
    );
  }

  mainItem(List<String> card) {
    return wrapGuesture(
      card,
      Stack(
        children: [
          Image.asset(
            card[0],
            height: 88,
            width: 121,
            fit: BoxFit.cover,
            alignment: Alignment.bottomCenter,
          ),
          Text(
            card[1],
            style: TextStyle(
              color: Colors.white,
              fontSize: 16.px,
              fontWeight: FontWeight.w600,
            ),
          ),
        ],
      ),
    );
  }

  wrapGuesture(List<String> card, Widget widget) {
    return GestureDetector(onTap: _ontap(), child: widget);
  }

  GestureTapCallback? _ontap() {
    //实现一个点击跳转功能
  }

  Widget doubleItem(List<String> card) {
    return Column(
      children: [
        Expanded(child: item([card[2], card[3]])),
        Expanded(child: item([card[4], card[5]])),
      ],
    );
  }

  Widget item(List<String> card) {
    return Padding(
      padding: EdgeInsets.only(right: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [subItem(card[0]), subItem(card[1])],
      ),
    );
  }

  subItem(String card) {
    return wrapGuesture(
      [card],
      Center(
        child: Text(card, style: TextStyle(color: Colors.white)),
      ),
    );
  }
}
